home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ada / c01oop.zip / ADAWKBK / SOL2-7.ADA < prev    next >
Text File  |  1992-08-25  |  2KB  |  71 lines

  1. -- Problem 2.7
  2. -- by Rick Conn
  3. with Text_IO;
  4. procedure Main is
  5.  
  6.   type BOOK is record
  7.     Title       : STRING(1..80);
  8.     Title_Last  : NATURAL;
  9.     Author      : STRING(1..80);
  10.     Author_Last : NATURAL;
  11.     Price       : FLOAT;
  12.     Year        : INTEGER;
  13.   end record;
  14.  
  15.   package Float_IO is new Text_IO.Float_IO (FLOAT);
  16.   package Int_IO is new Text_IO.Integer_IO (INTEGER);
  17.  
  18.   function Setup (Title  : in STRING;
  19.                   Author : in STRING;
  20.                   Price  : in FLOAT;
  21.                   Year   : in INTEGER) return BOOK is
  22.     Local_Book : BOOK;
  23.   begin
  24.     Local_Book.Title(1..Title'LENGTH) := Title;
  25.     Local_Book.Title_Last := Title'LENGTH;
  26.     Local_Book.Author(1..Author'LENGTH) := Author;
  27.     Local_Book.Author_Last := Author'LENGTH;
  28.     Local_Book.Price := Price;
  29.     Local_Book.Year  := Year;
  30.     return Local_Book;
  31.   end Setup;
  32.  
  33.   procedure Display (Item : in BOOK) is
  34.   begin
  35.     Text_IO.Put_Line ("Title: " & Item.Title(1..Item.Title_Last));
  36.     Text_IO.Put_Line ("  Author: " & Item.Author(1..Item.Author_Last));
  37.     Text_IO.Put ("  Price: $");
  38.       Float_IO.Put (Item.Price, 2, 2, 0);
  39.       Text_IO.New_Line;
  40.     Text_IO.Put ("  Year: ");
  41.       Int_IO.Put (Item.Year, 4);
  42.       Text_IO.New_Line;
  43.   end Display;
  44.  
  45. begin -- Main
  46.  
  47.   declare
  48.     My_Book   : BOOK;
  49.     His_Book  : BOOK;
  50.     Your_Book : BOOK;
  51.   begin  -- block
  52.     My_Book   := Setup ("War and Peace",
  53.                         "Tolstoy",
  54.                         39.95,
  55.                         1912);
  56.     His_Book  := Setup ("Software Engineering with Ada",
  57.                         "Booch",
  58.                         19.95,
  59.                         1987);
  60.     Your_Book := Setup ("Fun and Games",
  61.                         "Dick and Jane",
  62.                         5.95,
  63.                         1990);
  64.  
  65.     Display (My_Book);
  66.     Display (His_Book);
  67.     Display (Your_Book);
  68.   end;
  69.  
  70. end Main;
  71.